//
//  FDSameToAndroidTextFieldCustomView.m
//  FD
//
//  Created by xiaofang wang on 2019/1/20.
//  Copyright © 2019年 ZhiYuan Network. All rights reserved.
//

#import "FDSameToAndroidTextFieldCustomView.h"
#define k15Margin 15
@implementation FDSameToAndroidTextFieldCustomView

#pragma mark - 一 init

/**
 1-20 跟android一样。
 
 @param frame frame
 @param title 标题
 @return 返回一个“上面是标题，左边可能有按钮。中间是输入框,下边是灰色的线”的自定义view
 */
- (instancetype)initWithFrame:(CGRect)frame title:(NSString *)title {
    
    if (self = [super initWithFrame:frame]) {
        [self setupView];
        self.titleLb.text = title;
    }
    return self;
}
- (void)setupView {
    
    //上 topBgView(左边label,右边按钮按需显示)
    [self addSubview:self.topBgView];
    [self.topBgView addSubview:self.titleLb];
    
    //中 输入框
    [self addSubview:self.tf];
    
    //下:线
    [self addSubview:self.lineView];
}

#pragma mark - 二 layout
- (void)layoutSubviews {
    [super layoutSubviews];
    [self.topBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top);
        make.left.equalTo(self.mas_left).offset(k15Margin);
        make.right.equalTo(self.mas_right).offset(-k15Margin);
        make.height.mas_equalTo(22);
    }];
    [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.topBgView);
    }];
    
    
    //中
    [self.tf mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.topBgView.mas_bottom);
        make.left.equalTo(self.mas_left).offset(k15Margin);
        make.right.equalTo(self.mas_right).offset(-k15Margin);
        make.bottom.equalTo(self.lineView.mas_top);
//        make.height.mas_equalTo(22);
    }];
    
    
    //下
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(k15Margin);
        make.right.equalTo(self.mas_right).offset(-k15Margin);
        make.height.mas_equalTo(1);
        make.bottom.equalTo(self.mas_bottom).offset(-1);
    }];
}


#pragma mark - 三 getter
//上面的view
- (UIView *)topBgView {
    if (!_topBgView) {
        _topBgView = [[UIView alloc] init];
    }
    return _topBgView;
}
- (UILabel *)titleLb {
    if (!_titleLb) {
        _titleLb = [UILabel new];
        _titleLb.font = [UIFont systemFontOfSize:15.0];
        _titleLb.textColor = kLightGrayTextColor; //灰色字体
//        _titleLb.backgroundColor = [UIColor redColor];
    }
    return _titleLb;
}
//右侧按钮可能有可能，没有
//- (void)


//中间输入框
- (UITextField *)tf {
    if (!_tf) {
        _tf = [[UITextField alloc] init];
        _tf.font = [UIFont systemFontOfSize:15.0];
//        _tf.placeholder = @"对自己不满意就去改变";
    }
    return _tf;
}

//下边的线
- (UIView *)lineView {
    if (!_lineView) {
        _lineView = [UIView new];
        _lineView.backgroundColor = rgba(220,220,220,1.0);
    }
    return _lineView;
}
@end
